import React from 'react';
import DataTable from 'components/DataTable';
import Icon from 'components/Icon';
import Button from 'components/Button';
import Upload from "components/Upload";
import Editor from 'components/Editor';
import { Modal } from "antd";
export default (self, dict) => [
    {
        title: '分类',
        name: 'category',
        dict: dict.category,
        tableItem: {},
        formItem: {
            type: 'select',
            rules: [
                {
                    required: true,
                    message: '请选择类别'
                }
            ]
        },
        searchItem: {
            type: 'select',
            group: 'abc',
            width: 150,
        }
    },
    {
        title: '名称',
        name: 'name',
        tableItem: {},
        searchItem: {
            group: 'abc'
        },
        formItem: {
            rules: [
                {
                    required: true,
                    message: '请输入名称'
                }
            ]
        },
    },
    {
        title: '图标',
        name: 'icon',
        tableItem: {},
        formItem: {},
    },
    {
        title: '颜色',
        name: 'color',
        tableItem: {},
        formItem: {},
    },
    {
        title: '摘要',
        name: 'abstract',
        formItem: {
            type: 'textarea',
            rows: 4
        },
    },
    {
        title: '百科',
        name: 'content',
        formItem: {
            type: 'custom',
            render: (record, form) => {
                const { getFieldDecorator } = form;
                return (
                    <div>
                        {getFieldDecorator('content', {
                            initialValue: record && record.content
                        })(<Editor />)}
                    </div>
                )
            }
        },
    },
    {
        title: '图片',
        name: 'images',
        tableItem: {
            render: (value, record) => {
                return <DataTable.Oper>
                    <Upload name="file" multiple={true} accept="image/*"
                        action={"/adorn_pedia/" + record.id + "/upload_image/"}
                        data={(file) => {
                            return {
                                page: file.name.split(".")[0],
                            };
                        }}
                        onChange={(info) => {
                            if (info.file.status === "error") {
                                Modal.error({
                                    title: "内容上传失败",
                                    content: (
                                        <div>
                                            <p>sadasd</p>
                                        </div>
                                    ),
                                    onOk() { },
                                });
                            } else if (info.file.status === "done") {
                            }
                        }}
                    >
                        <Icon type="upload" style={{ color: 'red' }} />
                    </Upload>
                </DataTable.Oper>
            }
        }
    },
    {
        title: '缩略图',
        name: 'thumbnail_arr',
        formItem: {
            type: 'upload',
            listType: 'picture',
            action: '/system/upload/?savePath=adorn_pedia', // 后台接口 例：/uploadFile 会走代理
            fileName: 'file', // 后台接收的名字
            rules: [
                {
                    required: true,
                    message: '请选择图片'
                }
            ],
            maxFileSize: 1000, // 最大限制 kb
            max: 1
        }
    },
    {
        title: '操作',
        tableItem: {
            width: 90,
            fixed: 'right',
            render: (text, record) => (
                <DataTable.Oper>
                    <Button tooltip="修改" onClick={e => self.onUpdate(record)}>
                        <Icon type="edit" />
                    </Button>
                    <Button tooltip="删除" onClick={e => self.onDelete(record)}>
                        <Icon type="trash" />
                    </Button>
                    <Button tooltip="查看明细" onClick={e => self.onShowDetail(record)}>
                        <Icon type="screen-full" />
                    </Button>
                </DataTable.Oper>
            )
        }
    }
];
